//
//  DYMineHeaderView.m
//  kafuMerchant
//
//  Created by 帝云科技 on 2018/9/20.
//  Copyright © 2018年 帝云科技. All rights reserved.
//

#import "DYMineHeaderView.h"

@interface DYMineHeaderView ()

@property (nonatomic,strong)UIImageView *bgImageView;
@property (nonatomic,strong)UIImageView *headImageView;
@property (nonatomic,strong)UIButton *loginButton;
@property (nonatomic,strong)UIButton *registerButton;
@property (nonatomic,strong)UILabel *nameLabel;

@end


@implementation DYMineHeaderView

-(instancetype)initWithFrame:(CGRect)frame
{
    if (self=[super initWithFrame:frame]) {
        [self initView];
    }
    return self;
}
-(void)initView
{
    
    self.backgroundColor=WhiteColor;
    
    self.bgImageView = ({
        UIImageView *imageView=[Utils imageView];
        if (XHQ_iPhoneX) {
          imageView.image=IMG(@"bgx_mine_head");
        }else{
            imageView.image=IMG(@"bg_mine_head");
        }
        imageView;
    });
    
    self.headImageView=({
        UIImageView *imageView=[Utils imageViewWithImage:IMG(@"img_mine_head")];
        [imageView xhq_cornerRadius:BILIHEIGHT(27)];
        imageView;
    });
    
    self.loginButton = ({
        UIButton *button=[Utils createBtnWithType:UIButtonTypeCustom backgroundColor:ClearColor action:@selector(buttonClick:) target:self title:@"登录/" image:nil font:14 textColor:WhiteColor];
        button;
    });
    
    self.registerButton= ({
        UIButton *button=[Utils createBtnWithType:UIButtonTypeCustom backgroundColor:ClearColor action:@selector(buttonClick:) target:self title:@"注册" image:nil font:14 textColor:WhiteColor];
        button;
    });
    
    self.nameLabel = ({
        UILabel *label=[Utils labelWithTitleFontSize:14 textColor:WhiteColor alignment:1];
        label;
    });
    
    
    [self addSubview:self.bgImageView];
    [self addSubview:self.headImageView];
    [self addSubview:self.loginButton];
    [self addSubview:self.registerButton];
    [self addSubview:self.nameLabel];
    
    
    [self.bgImageView makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(UIEdgeInsetsMake(0, 0, BILIHEIGHT(90), 0));
    }];
    
    [self.headImageView makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.top.equalTo(BILIHEIGHT(77));
        make.width.height.equalTo(BILIHEIGHT(54));
    }];
    
    [self.loginButton makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(-kScreenWidth/2+BILIWIDTH(3));
        make.top.equalTo(self.headImageView.bottom).offset(BILIHEIGHT(5));
    }];
    
    
    [self.registerButton makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.loginButton.right);
        make.centerY.equalTo(self.loginButton);
    }];
    
    [self.nameLabel makeConstraints:^(MASConstraintMaker *make) {
       make.top.equalTo(self.headImageView.bottom).offset(BILIHEIGHT(5));
        make.centerX.equalTo(self);
    }];
    
    NSArray *titleArray=@[@"我要装修",@"我要收款",@"我要发卡",@"我要认证"];
    NSArray *imageArray=@[@"ic_zx_mine",@"ic_sk_mine",@"ic_fk_mine",@"ic_rz_mine"];
    
    for (NSInteger i=0; i<4; i++) {
        UIButton *button=[Utils createBtnWithType:UIButtonTypeCustom backgroundColor:ClearColor action:@selector(buttonClick:) target:self title:titleArray[i] image:imageArray[i] font:12 textColor:[UIColor xhq_aTitle]];
        [self addSubview:button];
   
        [button makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(i*kScreenWidth/4);
            make.top.equalTo(self.bgImageView.bottom);
            make.bottom.equalTo(0);
            make.width.equalTo(kScreenWidth/4);
        }];
        if (i==2) {
            [button placeImageTitlePosition:ZYButtonImagePositionTop space:BILIHEIGHT(16)];
        }else if (i==3){
            [button placeImageTitlePosition:ZYButtonImagePositionTop space:BILIHEIGHT(13)];
        }else{
             [button placeImageTitlePosition:ZYButtonImagePositionTop space:BILIHEIGHT(10)];
        }
//        [button placeImageTitlePosition:ZYButtonImagePositionTop space:BILIHEIGHT(10)];
    }
    
}
-(void)buttonClick:(UIButton *)button
{
    !self.mineBlock?:self.mineBlock(button.titleLabel.text);
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
